const db = wx.cloud.database();
const app = getApp();
const api = require("../../utils/api")
const getwxphone = require("../../utils/getwxphone")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pic: [{
        src: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic1.png',
        src1: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic1a.png',
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic2.png',
        src1: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic2a.png',
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic3.png',
        src1: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic3a.png',
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic4.png',
        src1: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic4a.png',
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic5.png',
        src1: 'http://sd.offcn.com/zg/wximg/2022/szyf/yytx/pic5a.png',
      },
    ],
    ontap1: !1,
    ontap2: !1,
    ontap3: !1,
    ontap4: !1,
    ontap5: !1,
    page:181
  },

  

  getPhoneNumber(e) {
    var _ = this;
    console.log(e)
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 21
    }

    getwxphone(e.detail.code, 51773, 'chaxun', info)
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })
  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  },
  login() {
    var _ = this;
    wx.showToast({
      title: '请先登录！',
      icon: 'none'
    })
    _.setData({
      fixed: 1
    })
  },

  ontap1: function () {
    var _ = this;
    wx.showModal({
      title: '提示',
      content: '是否需要推送公告发布提醒',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.requestSubscribeMessage({
            tmplIds: ['Xk4dWVhzxJ7hxYJbdJkPoSiklMfWZxFI8yTsOHjoLBg'], //报名提醒
            success(res) {
              console.log(res);
              db.collection('yytx').where({
                _openid: app.globalData.openid,
              }).get({
                success: res => {

                  db.collection('yytx').add({
                    data: {
                      ggfb: '1',
                      phone: wx.getStorageSync('yytxphone')
                    },
                    //添加成功的回调函数
                    success(res) {
                      console.log('cloud get success!')
                      wx.setStorageSync('ontap1', '1');
                      _.setData({
                        ontap1: 1
                      })


                    }
                  });
                },
              })
            },
            fail(res) {
              console.log(res);
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  ontap2: function () {
    var _ = this;
    wx.showModal({
      title: '提示',
      content: '是否需要推送报名确认提醒',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.requestSubscribeMessage({
            tmplIds: ['w5_eA0vhUx2pAWz29IjkqCPqgcT9qzS0itli0kbjt5Y'], //报名提醒
            success(res) {
              console.log(res);
              db.collection('yytx').where({
                _openid: app.globalData.openid,
              }).get({
                success: res => {

                  db.collection('yytx').add({
                    data: {
                      bmqr: '1',
                      phone: wx.getStorageSync('yytxphone')
                    },
                    //添加成功的回调函数
                    success(res) {
                      console.log('cloud get success!')
                      wx.setStorageSync('ontap2', '1');
                      _.setData({
                        ontap2: 1
                      })

                    }
                  });
                },
              })
            },
            fail(res) {
              console.log(res);
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    });

  },
  ontap3: function () {
    var _ = this;
    wx.showModal({
      title: '提示',
      content: '是否需要推送报名入口开通提醒',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.requestSubscribeMessage({
            tmplIds: ['8ycRosgkE-f_6Maexqr8BnDAE5JLeVKB2YbziUGegCU'], //报名序号查询
            success(res) {
              console.log(res);
              db.collection('yytx').where({
                _openid: app.globalData.openid,
              }).get({
                success: res => {

                  db.collection('yytx').add({
                    data: {
                      bmrk: '1',
                      phone: wx.getStorageSync('yytxphone')
                    },
                    //添加成功的回调函数
                    success(res) {
                      console.log('cloud get success!')
                      wx.setStorageSync('ontap3', '1');
                      _.setData({
                        ontap3: 1
                      })
                    }
                  });
                },
              })
            },
            fail(res) {
              console.log(res);
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  ontap4: function () {
    var _ = this;
    wx.showModal({
      title: '提示',
      content: '是否需要推送准考证打印提醒',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.requestSubscribeMessage({
            tmplIds: ['dBzhTF8vC2g5VOBM4nBhebnWR5YjMpBDVjI_1IOZ-BY'], //报名确认缴费
            success(res) {
              console.log(res);
              db.collection('yytx').where({
                _openid: app.globalData.openid,
              }).get({
                success: res => {

                  db.collection('yytx').add({
                    data: {
                      zkzdy: '1',
                      phone: wx.getStorageSync('yytxphone')
                    },
                    //添加成功的回调函数
                    success(res) {
                      console.log('cloud get success!')
                      wx.setStorageSync('ontap4', '1');
                      _.setData({
                        ontap4: 1
                      })
                    }
                  });
                },
              })
            },
            fail(res) {
              console.log(res);
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  ontap5: function () {
    var _ = this;
    wx.showModal({
      title: '提示',
      content: '是否需要推送成绩查询提醒',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.requestSubscribeMessage({
            tmplIds: ['ekHlzJyvEIUS7vhYcbIKK1NRdBiY4QSfWSTSysi3AvE'], //准考证打印
            success(res) {
              console.log(res);
              db.collection('yytx').where({
                _openid: app.globalData.openid,
              }).get({
                success: res => {

                  db.collection('yytx').add({
                    data: {
                      cjcx: '1',
                      phone: wx.getStorageSync('yytxphone')
                    },
                    //添加成功的回调函数
                    success(res) {
                      console.log('cloud get success!')
                      wx.setStorageSync('ontap5', '1');
                      _.setData({
                        ontap5: 1
                      })
                    }
                  });
                },
              })
            },
            fail(res) {
              console.log(res);
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  tokqcx() {
    var _ = this;
    wx.navigateTo({
      url: '../zwjs/zwjs?area=' + _.data.area + '&agent=' + _.data.agent,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _ = this;
    console.log(options)
    _.setData({
      area: options.area,
      agent: options.agent
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
    var ontap1 = wx.getStorageSync('ontap1')
    var ontap2 = wx.getStorageSync('ontap2')
    var ontap3 = wx.getStorageSync('ontap3')
    var ontap4 = wx.getStorageSync('ontap4')
    var ontap5 = wx.getStorageSync('ontap5')
    var yytxphone = wx.getStorageSync('yytxphone')
    if (yytxphone) {
      _.setData({
        yytxphone: 1
      })
    }
    if (ontap1) {
      _.setData({
        ontap1: 1
      })
    }
    if (ontap2) {
      _.setData({
        ontap2
      })
    }
    if (ontap3) {
      _.setData({
        ontap3
      })
    }
    if (ontap4) {
      _.setData({
        ontap4
      })
    }
    if (ontap5) {
      _.setData({
        ontap5
      })
    }


    wx.login({
      //成功放回
      success:(res)=>{
        console.log(res);
        let code=res.code
        console.log(code)
        wx.request({
          url: 'https://zg99.offcn.com/index/index/getsesionkey?actid=51773&callback=?',
          data:{

            code:code
          },
          success:(res)=>{
            console.log(res);
          }
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})